package com.huilan.hgt.controller;

import com.huilan.hgt.entity.User;
import com.huilan.hgt.util.Constants;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;

import java.util.Random;


/**
 * @author ghy
 * @date 2018-11-05 11:14 AM
 **/
@Slf4j
@Controller
public class IndexController {


    @GetMapping({"/", "/index.do"})
    public String index() {
        return "index";
    }


    /**
     * 调整系统登录页
     *
     * @return
     */
    @GetMapping(value = "/login.do")
    public String login(ModelMap modelMap) {
        return "login";
    }


    /**
     * 跳转PIN码验证页面
     */
    @GetMapping(value = "/verifyPage.do")
    public String verifyPage(ModelMap modelMap){
        User user = Constants.getCurrentUser();
        String code = Constants.encryptionPin(user.getPin());
        modelMap.put("code",code);
        return "login_v2";
    }

    /**
     * 验证PIN码
     */
    @PostMapping(value = "/verifyPinCode.do")
    public String verifyPinCode(Integer pin){
        User user = Constants.getCurrentUser();
        if(pin.equals(user.getPin())){
            return "redirect:/index.do";
        }
        return "redirect:/verifyPage.do";
    }
}
